document.getElementById('searchButton').addEventListener('click', function(event) {
    event.preventDefault(); // 阻止按钮默认行为

    // 获取搜索框中的值
    var movieType = document.getElementById('movieType').value;
    var movieName = document.getElementById('movieName').value;
    var movieUptime = document.getElementById('movieUptime').value;

    // 构建查询字符串
    var queryString = '?type=' + encodeURIComponent(movieType) +
        '&fname=' + encodeURIComponent(movieName) +
        '&uptime=' + encodeURIComponent(movieUptime);

    // 发起后端请求
    fetch('/movie_fd' + queryString)
        .then(response => response.json())
        .then(data => {
            // 处理返回的数据
            var searchResultsDiv = document.getElementById('searchResults');
            searchResultsDiv.innerHTML = ''; // 清空之前的结果

            if (data.length === 0) {
                searchResultsDiv.textContent = '未找到符合条件的电影。';
            } else {
                data.forEach(function(movie) {
                    var movieInfo = document.createElement('div');
                    movieInfo.textContent = '电影名称：' + movie.movieName + '，类型：' + movie.type + '，上映时间：' + movie.uptime;
                    searchResultsDiv.appendChild(movieInfo);
                });
            }
        })
        .catch(error => {
            console.error('发生错误：', error);
        });
});